﻿
//格式化是否是负责人
var fnFormatText = function (elCell, oRecord, oColumn, sData) {
    var pid = oRecord.getData(const_entityID);
    var PostLevel = oRecord.getData("PostLevel");
    if (sData == pid && PostLevel==0) {
        elCell.innerHTML = "<font color='red'>是</font>";
    } else {
        elCell.innerHTML = "否";
    }
}

//职位说明
var fnPostNotes = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //debugger;
    var postName = record.getData("PostName");
    var postID = record.getData(const_entityID);
    const_EditEntity = "DatPostNotes";
    document.getElementById("dialog1_h").innerHTML = postName + "_职位说明";
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&postID=" + postID + "&postName=" + postName;
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//技能要求
var fnSkillRequire = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var postID = record.getData(const_entityID);
    var postName = record.getData("PostName");
    var pagetitle = postName + "_技能要求";
    document.getElementById("dialog1_h").innerHTML = pagetitle;
    //var url = "../Extend/YUIDataTableList.aspx?entity=V_datSkillLevel&order=SkillName,[level],SkillLevel&functionID=01e63717-1778-4613-88c0-1e1f3ced5ec8&condition=postID='" + postID + "'" + "&postID=" + postID + "&postName=" + postName;
    var url = "../Extend/YUIDataTableList.aspx?entity=V_DatPostSkillRequire&order=postname,SkillName,[level],SkillLevel&functionID=e8c7135a-b00b-4280-a99b-529cab7f249e&condition=postID='" + postID + "'" + "&postID=" + postID + "&postName=" + postName + "&action=SavePostSkill" + "&strEntity=DatPostSkillRequire";
  
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, url);
}

//职位编制
var fnPostHumanEstablishment = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var postName = record.getData("PostName");
    var postID = record.getData(const_entityID);
    const_EditEntity = "hrPostHumanEstablishment";
    document.getElementById("dialog1_h").innerHTML = postName+"_职位编制";
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&postID=" + postID + "&postName=" + postName;
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//新增职位
/* 对应的方法和ID*/
var fnCustomAdd = function () {

}
var fnAddPosition = function () {
    if (fkey != "") {
        _fn = GetSelected;
        document.getElementById("EditUIWindow1").src = "../../EditWidows/OrganizationalManager/CreatePosition.aspx?id=" + fkey + "";
        YAHOO.example.container.dialog2.show();
    }
    else {
        alert("操作无效,请先选择左侧组织架构树");
    }
}
//修改职务
var fnEditDuty = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var vid = record.getData(const_entityID);
    var vType = record.getData("PhraseID");
    var vDuty = record.getData("IDS");
    if (vid != "") {
        var pagetitle = "职位中职务编辑";
        document.getElementById("EditUIWindow").src = "../../EditWidows/OrganizationalManager/EditDuty.aspx?vFkey=" + fkey + "&vType=" + vType + "&vDuty=" + vDuty + "&type=1&r=" + Math.random() + "&entity=DatPostDuty&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
        YAHOO.example.container.dialog1.show();
        document.getElementById("yui-gen31-button").style.display = "block";
    }
    Native("", fkey);
}
//取消负责人
var fnModifyM = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    /// <reference path="../EditWidows/OrganizationalManager/DataProcessin.aspx" />   
    var SetManagerURL = "../EditWidows/OrganizationalManager/DataProcessin.aspx";
    var vid = record.getData(const_entityID);
    var dpid = record.getData("DeptID");
    if (vid != undefined && dpid != undefined) {
        if (confirm("您确定取消该职位为部门管理岗位吗？")) {
            var SaveUrl = SetManagerURL + "?r=" + Math.random() + "&cancel=0&action=update&entity=DatPost&manager=" + vid + "&json=&deptid=" + dpid;
            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str == "1") {
                            alert("设置成功!");
                            Native("", fkey);
                            // RefreshData();
                        }
                        else {
                            alert(str + "\n" + "操作失败!");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
    }
}
//设置负责人
var fnSetManager = function () {
    var recordID = myDataTable.getSelectedRows()[0];              
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }      
    /// <reference path="../EditWidows/OrganizationalManager/DataProcessin.aspx" />   
    var SetManagerURL = "../EditWidows/OrganizationalManager/DataProcessin.aspx";
    var vid = record.getData(const_entityID);
    var dpid = record.getData("DeptID");
    if (vid != undefined && dpid != undefined) {
        if (confirm("您确定设置该职位为部门管理岗位吗？")) {
            var SaveUrl = SetManagerURL + "?r=" + Math.random() + "&action=update&entity=DatPost&manager=" + vid + "&json=&deptid=" + dpid;
            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str == "1") {
                            alert("设置成功!");
                            Native("", fkey);
                            // RefreshData();
                        }
                        else {
                            alert(str + "\n" + "操作失败!");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
    }
}

//职位对应职级
var fnDatPostGrade = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    var vName = record.getData("PostName");
    if (record == null) {
        alert("请选择一条记录!");
        return;
    } else {
        var vid = record.getData(const_entityID);
        if (vid != "") {
            var pagetitle = "职位对应职级";
            document.getElementById("EditUIWindow").src = "../../EditWidows/OrganizationalManager/AddDutyGrade.aspx?&r=" + Math.random() + "&entity=DatPostDutygrade&name=" + encodeURI(vName) + "&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
            YAHOO.example.container.dialog1.show();
            document.getElementById("yui-gen31-button").style.display = "block";
        }
        Native("", fkey);
    }
}


